package _10_binary_tree.getdepth;

import _10_binary_tree.TreeNode;
import org.junit.Test;

/**
 * @author: mornd
 * @dateTime: 2023/6/12 - 0:22
 * 求二叉树最大深度
 *
 *         深度为3      深度为1
 *          1             1
 *         /\
 *        2  3
 *          /\
 *         4  5
 */
public class MaxDepthTest {
    @Test
    public void test() {

//        TreeNode root2 = new TreeNode(1, new TreeNode(2), new TreeNode(3));
//        System.out.println(maxDepth(root2));

        TreeNode root = new TreeNode(1, new TreeNode(2), new TreeNode(3,
                new TreeNode(4), new TreeNode(5)));
        System.out.println(maxDepth(root));
    }

    public int maxDepth(TreeNode root) {
        if(root == null) {
            return 0;
        }
        int l = maxDepth(root.left);
        int r = maxDepth(root.right);
        return Math.max(l, r) + 1;
    }

}
